package com.icreate.bolt;

import org.apache.storm.task.OutputCollector;
import org.apache.storm.task.TopologyContext;
import org.apache.storm.topology.OutputFieldsDeclarer;
import org.apache.storm.topology.base.BaseRichBolt;
import org.apache.storm.tuple.Tuple;

import java.io.Console;
import java.util.Map;

/**
 * Created by icreate on 2017/5/15.
 */
public class CountBolt extends BaseRichBolt {
    private OutputCollector collector;
    private int count = 0;

    @Override
    public void prepare(Map map, TopologyContext topologyContext, OutputCollector outputCollector) {
        this.collector = outputCollector;
    }

    @Override
    public void execute(Tuple tuple) {
        this.count = (int) tuple.getValueByField("number") + this.count;
    }

    @Override
    public void declareOutputFields(OutputFieldsDeclarer outputFieldsDeclarer) {

    }

    @Override
    public void cleanup() {
        super.cleanup();
        System.out.println("---------------count:" + this.count);
    }
}
